package com.hmall.search.controller;

import com.hmall.common.client.ItemClient;
import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.Item;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService service;


    /**
     * 拿到索引库中所有数据
     * @param params 请求参数
     * @return 返回页面对象
     */
    @PostMapping("list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params) {
        return service.search(params);
    }


    /**
     *
     */
    @PostMapping("filters")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams params){
        return service.getFilters(params);
    }

    /**
     * 自动补全
     * @param key 搜索关键字
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String key) {
        return service.suggetions(key);
    }
}
